# Maintainer: David Runge <dvzrv@archlinux.org>

_name=orjson
pkgname=python-orjson
pkgver=3.8.11
pkgrel=2
pkgdesc="Fast, correct Python JSON library supporting dataclasses and datetimes"
arch=(loong64 x86_64)
url="https://github.com/ijl/orjson"
license=(
  Apache
  MIT
)
depends=(
  gcc-libs
  glibc
  python
)
makedepends=(
  maturin
  python-installer
  rust
)
checkdepends=(
  python-arrow
  python-pendulum
  python-psutil
  python-pytest
  python-pytz
  python-xxhash
)
source=($url/archive/$pkgver/$_name-$pkgver.tar.gz)
sha512sums=('b59cf2675c8d1e4cfd3b9cf3525b360a97c2191a8817e6df368ffed02095bc012c350df8ed57c992eec63b3233e67b528d50f8ebc45c78bc72b467c1d732f784')
b2sums=('acdaed477e21396b34f3be8e4c8f91604284a0b3a1320c08acaf51a01fa06d108a3d88f91edfaf895a596086e13e79b6faeb13c6f25ff9f2e28aa780adddf27c')

build() {
  cd $_name-$pkgver
  find -name Cargo.lock -exec rm -f {} \;
  mkdir -p .cargo
  cat > .cargo/config.toml <<EOF
[source.crates-io]
registry = "https://gitee.com/yetist/crates.io-index"
EOF
  maturin build --release --strip
}

check() {
  local _site_packages=$(python -c "import site; print(site.getsitepackages()[0])")

  cd $_name-$pkgver
  python -m installer --destdir=test_dir target/wheels/*.whl
  export PYTHONPATH="test_dir/$_site_packages:$PYTHONPATH"
  pytest -vv
}

package() {
  cd $_name-$pkgver
  python -m installer --destdir="$pkgdir" target/wheels/*.whl
  install -vDm 644 {CHANGELOG,README}.md -t "$pkgdir/usr/share/doc/$pkgname/"
  install -vDm 644 LICENSE-* -t "$pkgdir/usr/share/licenses/$pkgname/"
}
